/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T20A_tobitreg_vocabulary.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}/panel_RR_indexes.dta", clear
    estimates clear

	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	local child "zptevir_irtscore2 zcog_index zsoc_index" 

	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	

/*******************************************************************************
Table A20: Tobit regression for the impacts on child vocabulary index at endline
*******************************************************************************/


*** Vocabulary
local thresh "2 5 10 15 20 25 30 40 50 60 75 90"
foreach x of local thresh {
egen p_`x' = pctile(zptevir_irtscore2), p(`x')
g zptevir_irtscore2_p`x'=.
replace zptevir_irtscore2_p`x'=zptevir_irtscore2 if zptevir_irtscore2>=p_`x'
replace zptevir_irtscore2_p`x'=p_`x' if zptevir_irtscore2<p_`x'
replace zptevir_irtscore2_p`x'=p_`x' if attrite==1

}
su p_*

/*
         p_2 |      3,579   -2.340379           0  -2.340379  -2.340379
         p_5 |      3,579    -1.74122           0   -1.74122   -1.74122
        p_10 |      3,579   -1.291231           0  -1.291231  -1.291231
        p_15 |      3,579   -.9876608           0  -.9876608  -.9876608
        p_20 |      3,579   -.7516358           0  -.7516358  -.7516358
-------------+---------------------------------------------------------
        p_25 |      3,579   -.5644923           0  -.5644923  -.5644923
        p_30 |      3,579   -.3810451           0  -.3810451  -.3810451
        p_40 |      3,579   -.0988751           0  -.0988751  -.0988751
        p_50 |      3,579    .1382982           0   .1382982   .1382982
        p_60 |      3,579    .3396899           0   .3396899   .3396899
-------------+---------------------------------------------------------
        p_75 |      3,579    .6474751           0   .6474751   .6474751
        p_90 |      3,579     .998885           0    .998885    .998885

*/

xi: xtreg zptevir_irtscore2 i.TIPO_old i.sexo_old, fe i(CENTRO_SALUD_old)
estimates store lang_tot
xi: xttobit zptevir_irtscore2_p2 i.TIPO_old i.sexo_old, ll(-2.340379) i(CENTRO_SALUD_old)
estimates store lang_p2
xi: xttobit zptevir_irtscore2_p5 i.TIPO_old i.sexo_old, ll( -1.74122) i(CENTRO_SALUD_old)
estimates store lang_p5
xi: xttobit zptevir_irtscore2_p10 i.TIPO_old i.sexo_old, ll(-1.291231) i(CENTRO_SALUD_old)
estimates store lang_p10
xi: xttobit zptevir_irtscore2_p15 i.TIPO_old i.sexo_old, ll(-.9876608 ) i(CENTRO_SALUD_old)
estimates store lang_p15
xi: xttobit zptevir_irtscore2_p20 i.TIPO_old i.sexo_old, ll(-.7516358) i(CENTRO_SALUD_old)
estimates store lang_p20
xi: xttobit zptevir_irtscore2_p25 i.TIPO_old i.sexo_old, ll(-.5644923) i(CENTRO_SALUD_old)
estimates store lang_p25
xi: xttobit zptevir_irtscore2_p30 i.TIPO_old i.sexo_old, ll(-.3810451 ) i(CENTRO_SALUD_old)
estimates store lang_p30
xi: xttobit zptevir_irtscore2_p40 i.TIPO_old i.sexo_old, ll(-.0988751  ) i(CENTRO_SALUD_old)
estimates store lang_p40
xi: xttobit zptevir_irtscore2_p50 i.TIPO_old i.sexo_old, ll(.1382982 ) i(CENTRO_SALUD_old)
estimates store lang_p50
xi: xttobit zptevir_irtscore2_p60 i.TIPO_old i.sexo_old, ll( .3396899 ) i(CENTRO_SALUD_old)
estimates store lang_p60
xi: xttobit zptevir_irtscore2_p75 i.TIPO_old i.sexo_old, ll(.6474751) i(CENTRO_SALUD_old)
estimates store lang_p75
xi: xttobit zptevir_irtscore2_p90 i.TIPO_old i.sexo_old, ll(.998885) i(CENTRO_SALUD_old)
estimates store lang_p90

** Table A20 **
esttab lang_tot lang_p5 lang_p10 lang_p20 lang_p30 lang_p40 lang_p50 /*
*/ using "$out_tables/appendix/T20A_tobitreg_vocabulary.csv", replace f /*
*/ keep(_ITIPO_old_2 _ITIPO_old_3) /*
*/ cells("b(fmt(3)star)" "se(fmt(3)par)") /*
*/ star(* 0.10 ** 0.05 *** 0.01) /*
*/ stats(r2 N, fmt(2 0) labels("R-squared" "Observations" )) legend	/*
*/ mtitles("OLS" "TOBIT 5%" "TOBIT 10%" "TOBIT 20%" "TOBIT 30%" "TOBIT 40%" "TOBIT 50%"  ) /*
*/ varlabels(_ITIPO_old_2 "NEP-B" _ITIPO_old_3 "NEP-I")
		
drop p_*
